<template>
	<div class="radio-inputs">
		<label class="radio">
			<input value="private" name="value-radio" id="value-1" type="radio" v-model="currentValue" @click="clickPrivate"
				checked />
			<span class="name">私有</span>
		</label>
		<label class="radio">
			<input value="public" name="value-radio" id="value-2" type="radio" v-model="currentValue" @click="clickPublic" />
			<span class="name">公有</span>
		</label>
	</div>
</template>

<script>
	export default {
		props: {
			// Receive bPublic value from the parent component
			bPublic: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// Set initial value based on bPublic
				currentValue: this.bPublic ? "public" : "private"
			};
		},

		mounted() {
			// this.clickPrivate(); // 应该根据currentValue的值初始化状态
		},
		methods: {
			clickPrivate() {
				this.$emit('update-bPublic', false, event);
				console.log('切换到私有模式');
			},
			clickPublic() {
				this.$emit('update-bPublic', true, event);
				console.log('切换到公有模式');
			},
			// 主动设置radio状态
			setState(newValue) {
				console.log('setState', newValue);
				this.currentValue = newValue ? "public" : "private";
			},
			//获取radio状态
			getState() {
				return this.currentValue === "public";
			}
		},
	};
</script>
<style scoped>
	/* Combine the styles */
	.radio-inputs {
		--container_width: 140px;
		position: relative;
		display: flex;
		align-items: center;
		border-radius: 10px;
		background-color: #eee;
		box-sizing: border-box;
		padding: 0.25rem;
		width: var(--container_width);
		font-size: 14px;
		height: 46px;
		overflow: hidden;
		border: 1px solid rgba(53, 52, 52, 0.226);
	}

	.radio-inputs .radio {
		flex: 1 1 auto;
		text-align: center;
	}

	.radio-inputs .radio input {
		display: none;
	}

	.radio-inputs .radio .name {
		display: flex;
		cursor: pointer;
		align-items: center;
		justify-content: center;
		border-radius: 4px;
		border: none;
		padding: 0.5rem 0;
		color: rgba(51, 65, 85, 1);
		transition: all 0.15s ease-in-out;
	}

	.radio-inputs .radio input:checked+.name {
		background-color: #fff;
		font-weight: 600;
	}
</style>